﻿namespace AntDesignProCore.MVC
{
  public static class AuditContext
  {
    private static readonly AsyncLocal<Dictionary<string, object>> _auditData = new();

    public static void Set(string key, object value)
    {
      if (_auditData.Value == null)
      {
        _auditData.Value = new Dictionary<string, object>();
      }

      _auditData.Value[key] = value;
    }

    public static object? Get(string key)
    {
      if (_auditData.Value != null && _auditData.Value.TryGetValue(key, out var value))
      {
        return value;
      }
      return null;
    }
  }
}
